package dto

import (
	"go-admin/app/admin/models"

	"go-admin/common/dto"
	common "go-admin/common/models"
)

type SysMemberGetPageReq struct {
	dto.Pagination `search:"-"`
	TypeId         int    `form:"typeId" search:"type:exact;column:type_id;table:sys_member" comment:"会员类型"`
	Username       string `form:"username" search:"type:contains;column:username;table:sys_member" comment:"会员名"`
	NickName       string `form:"nickName" search:"type:contains;column:nick_name;table:sys_member" comment:"昵称"`
	Phone          string `form:"phone" search:"type:contains;column:phone;table:sys_member" comment:"手机号"`
	Sex            string `form:"sex" search:"type:exact;column:sex;table:sys_member" comment:"性别"`
	Email          string `form:"email" search:"type:contains;column:email;table:sys_member" comment:"邮箱"`
	Status         string `form:"status" search:"type:exact;column:status;table:sys_member" comment:"状态"`
	MemberType     `search:"type:left;on:type_id:id;table:sys_member;join:sys_member_type"`
	SysMemberOrder
}

type SysMemberOrder struct {
	MemberIdOrder  string `search:"type:order;column:id;table:sys_member" form:"memberIdOrder"`
	UsernameOrder  string `search:"type:order;column:username;table:sys_member" form:"usernameOrder"`
	StatusOrder    string `search:"type:order;column:status;table:sys_member" form:"statusOrder"`
	CreatedAtOrder string `search:"type:order;column:created_at;table:sys_member" form:"createdAtOrder"`
}

type MemberType struct {
	TypeId string `search:"type:contains;column:id;table:sys_member_type" form:"typeId"`
}

func (m *SysMemberGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type ResetSysMemberPwdReq struct {
	Id       int    `json:"id" comment:"会员ID" vd:"$>0"` // 会员ID
	Password string `json:"password" comment:"密码" vd:"len($)>0"`
	common.ControlBy
}

func (s *ResetSysMemberPwdReq) GetId() interface{} {
	return s.Id
}

func (s *ResetSysMemberPwdReq) Generate(model *models.SysMember) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.Password = s.Password
}

type UpdateSysMemberAvatarReq struct {
	Id     int    `json:"id" comment:"会员ID" vd:"len($)>0"` // 会员ID
	Avatar string `json:"avatar" comment:"头像" vd:"len($)>0"`
	common.ControlBy
}

func (s *UpdateSysMemberAvatarReq) GetId() interface{} {
	return s.Id
}

func (s *UpdateSysMemberAvatarReq) Generate(model *models.SysMember) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.Avatar = s.Avatar
}

type UpdateSysMemberStatusReq struct {
	Id     int    `json:"id" comment:"会员ID" vd:"$>0"` // 会员ID
	Status string `json:"status" comment:"状态" vd:"len($)>0"`
	common.ControlBy
}

func (s *UpdateSysMemberStatusReq) GetId() interface{} {
	return s.Id
}

func (s *UpdateSysMemberStatusReq) Generate(model *models.SysMember) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.Status = s.Status
}

type SysMemberInsertReq struct {
	Id       int    `json:"id" comment:"会员ID"` // 会员ID
	TypeId   int    `json:"typeId" comment:"会员类型" default:"0"`
	Username string `json:"username" comment:"会员名" vd:"len($)>0"`
	Password string `json:"password" comment:"密码"`
	NickName string `json:"nickName" comment:"昵称" vd:"len($)>0"`
	Phone    string `json:"phone" comment:"手机号" vd:"len($)>0"`
	Avatar   string `json:"avatar" comment:"头像"`
	Sex      string `json:"sex" comment:"性别"`
	Email    string `json:"email" comment:"邮箱" vd:"len($)>0,email"`
	Remark   string `json:"remark" comment:"备注"`
	Status   string `json:"status" comment:"状态" default:"1"`
	common.ControlBy
}

func (s *SysMemberInsertReq) Generate(model *models.SysMember) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.TypeId = s.TypeId
	model.Username = s.Username
	model.Password = s.Password
	model.NickName = s.NickName
	model.Phone = s.Phone
	model.Avatar = s.Avatar
	model.Sex = s.Sex
	model.Email = s.Email
	model.Remark = s.Remark
	model.Status = s.Status
}

func (s *SysMemberInsertReq) GetId() interface{} {
	return s.Id
}

type SysMemberUpdateReq struct {
	Id       int    `json:"id" comment:"会员ID"`                 // 会员ID
	TypeId   int    `json:"typeId" comment:"会员类型" default:"0"` // 会员类型
	Username string `json:"username" comment:"会员名" vd:"len($)>0"`
	NickName string `json:"nickName" comment:"昵称" vd:"len($)>0"`
	Phone    string `json:"phone" comment:"手机号" vd:"len($)>0"`
	Avatar   string `json:"avatar" comment:"头像"`
	Sex      string `json:"sex" comment:"性别"`
	Email    string `json:"email" comment:"邮箱" vd:"len($)>0,email"`
	Remark   string `json:"remark" comment:"备注"`
	Status   string `json:"status" comment:"状态" default:"1"`
	common.ControlBy
}

func (s *SysMemberUpdateReq) Generate(model *models.SysMember) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.TypeId = s.TypeId
	model.Username = s.Username
	model.NickName = s.NickName
	model.Phone = s.Phone
	model.Avatar = s.Avatar
	model.Sex = s.Sex
	model.Email = s.Email
	model.Remark = s.Remark
	model.Status = s.Status
}

func (s *SysMemberUpdateReq) GetId() interface{} {
	return s.Id
}

type SysMemberById struct {
	dto.ObjectById
	common.ControlBy
}

func (s *SysMemberById) GetId() interface{} {
	if len(s.Ids) > 0 {
		s.Ids = append(s.Ids, s.Id)
		return s.Ids
	}
	return s.Id
}

func (s *SysMemberById) GenerateM() (common.ActiveRecord, error) {
	return &models.SysMember{}, nil
}

// PassWord 密码
type MemberPassWord struct {
	NewPassword string `json:"newPassword" vd:"len($)>0"`
	OldPassword string `json:"oldPassword" vd:"len($)>0"`
}
